﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ResxCrunch.Properties;

namespace ResxCrunch
{
    /// <summary>
    /// Trial splash form class
    /// </summary>
    public partial class FrmTrialSplash : Form
    {
        /// <summary>
        /// Gets or sets the trial days are left.
        /// If none, the user is forced to register
        /// </summary>
        /// <value>The trial days left.</value>
        public int TrialDaysLeft
        {
            get;
            set;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="FrmTrialSplash"/> class.
        /// </summary>
        public FrmTrialSplash()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Handles the Load event of the FrmTrialSplash control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void FrmTrialSplash_Load(object sender, EventArgs e)
        {
            lblDaysLeft.Text = this.TrialDaysLeft.ToString();

            if (this.TrialDaysLeft <= 0)
            {
                btnContinue.Enabled = false;
            }
        }

        /// <summary>
        /// Handles the Click event of the btnEnterKey control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void btnEnterKey_Click(object sender, EventArgs e)
        {
            FrmActivateLicense fActivate = new FrmActivateLicense();

            if (fActivate.ShowDialog() == DialogResult.OK)
            {
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }

        /// <summary>
        /// Handles the Click event of the btnPurchase control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void btnPurchase_Click(object sender, EventArgs e)
        {
            try
            {
                System.Diagnostics.Process.Start(Settings.Default.PurchaseUrl);
            }
            catch (Exception)
            {
                MessageBox.Show(this, string.Format("We are sorry, an error occured while opening the webpage '{0}'. Please navigate manually to the address or contact us.", Settings.Default.PurchaseUrl), Settings.Default.AppName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }

        private void btnContinue_Click(object sender, EventArgs e)
        {
            // Continue with triAL
            this.DialogResult = DialogResult.Retry;
            this.Close();
        }
    }
}
